package com.zenni.core;

import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import com.zenni.core.MainPageVariables;
import org.openqa.selenium.support.ui.Select;
import org.testng.Assert;

import java.util.concurrent.TimeUnit;

/**
 * Created by douglasj on 2/15/16.
 */
public class MainPageFunction {
    private WebDriver driver;
    public MainPageFunction(WebDriver driver) throws InterruptedException{
        this.driver = driver;
    }
    public void goToMainPage() throws InterruptedException{
        driver.get(MainPageVariables.main_page_url);
        driver.manage().window().maximize();
        driver.manage().timeouts().pageLoadTimeout(50, TimeUnit.SECONDS);
    }
    public void goToWomanPage() throws Exception{
        System.out.println("click the woman link in home page");
        if(driver.findElement(By.xpath("//header[@id = 'new-top-navigation']/nav/div/ul/li/button")).isDisplayed()){
            driver.findElement(By.xpath("//header[@id = 'new-top-navigation']/nav/div/ul/li/button")).click();
            Thread thread = new Thread();
            thread.sleep(3000);
            JavascriptExecutor js = (JavascriptExecutor)driver;
            js.executeScript("document.getElementsByClassName(\"nav-women\")[1].click()");
            thread.sleep(3000);
        }else{
            JavascriptExecutor js = (JavascriptExecutor)driver;
            js.executeScript("document.getElementsByClassName(\"nav-women\")[0].click()");}
        /*driverUtils.waitTillElementExistsByXpath(driver,MainPageVariables.women_link_xpath_main_page,3000);
        driver.findElement(By.xpath(MainPageVariables.women_link_xpath_main_page)).click();*/
        Assert.assertTrue(driver.findElement(By.xpath("//header[@id = 'new-top-navigation']/nav/div/ul/li/button")).isDisplayed());
    }
}
